﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
using System.Data;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;

public partial class CRM_Store_ERP_InStoreEdit : BasePage
{
    public DataTable ViewState_InStoreList
    {
        get
        {
            return ViewState["ViewState_InStoreList"] as DataTable;
        }
        set
        {
            ViewState["ViewState_InStoreList"] = value;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int c = BindCenterStore(Store_Rome, Request.QueryString["ptabid"]);
            if (c > 0)
                extcomb_StoreRoomId.SelectedIndex = 0;
            string objid = ViewState_ObjID = string.IsNullOrEmpty(Request.QueryString["ObjId"]) ? "Add" : Request.QueryString["ObjId"];
            ShowEditInfo(objid);
        }
    }

    protected void extBtn_AddItem_Click(object sender, DirectEventArgs e)
    {
        if (extcomb_SupplyId.Text == "")
        {
            X.Msg.Alert("系统提示", "请先选择供货商！").Show();
            return;
        }
        if (extcomb_StoreRoomId.Text == "")
        {
            X.Msg.Alert("系统提示", "请先选择库房！").Show();
            return;
        }
        string Url = G_Url_allstring + "/CRM_Store/ERP_InStoreAddCargo.aspx?ptabid=" + Request.QueryString["tabid"] + ",Store1";
        ResourceManager1.AddScript("popTopwinWithId('CargoSelect','" + Url + "&ObjId=Add&supplier=" + extcomb_SupplyId.SelectedItem.Value + "&storeroomId=" + extcomb_StoreRoomId.SelectedItem.Value + "', '添加入库商品', 800, 600,AfterOperate);");
    }

    private void ShowEditInfo(string objid)
    {
        if (objid == "Add")
        {
            exttxtf_InUserName.Text = BS_LoginUserName;
            exthidn_InUser.Text = BS_LoginUserID;
            exttxtf_InDate.Text = DateTime.Now.ToDateTimeString();
            ViewState_InStoreList = CRMMis.BLL.ERP_ExportDetail.GetList(" 1=2 ").Tables[0];
        }
        else
        {
            var InstoreModel = CRMMis.BLL.ERP_ExportBll.GetList("ExportBillId=" + objid).Tables[0];
            if (InstoreModel.Rows.Count > 0)
            {
                DataRow row = InstoreModel.Rows[0];
                int State = Convert.ToInt32(row["State"]);
                //根据状态控制
                if (State != 1)
                    extBtn_CheckInfo.Hidden = true;
                if (State > 0)
                {
                    extBtn_SubmitInfo.Hidden = true;
                    extBtn_Save.Hidden = true;
                    extBtn_AddItem.Hidden = extBtn_DeleteItem.Hidden = extFuf_ImportExcel.Hidden = true;
                    SetContainerReadOnly(formPanel, true);
                    //gridPanel_listdata.ColumnModel.Columns[1].Editable =                //商品名称
                    //    gridPanel_listdata.ColumnModel.Columns[6].Editable = false;     //数量
                }
                if (State > 1)
                {
                    extBtn_CheckInfo.Hidden = true;
                }

                SetContainer(formPanel, InstoreModel);
                //单独绑定供货商
                DataTable suppData = CRMMis.BLL.ERP_Supply.GetList("SupplyID=" + row["SupplyId"], "SupplyName,Spell,Address").Tables[0];
                Store_Supply.DataSource = suppData;
                Store_Supply.DataBind();
                //绑定详情列表
                ViewState_InStoreList = CRMMis.BLL.ERP_ExportDetail.GetList(" DExportBillId=" + objid, "OrderId").Tables[0];
                Store1.DataSource = ViewState_InStoreList;
                Store1.DataBind();
                extcomb_SupplyId.ReadOnly = extcomb_StoreRoomId.ReadOnly = ViewState_InStoreList.Rows.Count > 0;

            }
        }
    }
    
    protected void StoreSupply_Refresh(object sender, StoreRefreshDataEventArgs e)
    {
        var qStr = GetSupplyQryString();
        int recordcount = CRMMis.BLL.ERP_Supply.GetRecorderCount(qStr);
        int PageSize = extcomb_SupplyId.PageSize;
        int CurPage = e.Start / PageSize + 1;
        e.Total = recordcount;
        DataTable suppData = CRMMis.BLL.ERP_Supply.GetPageList(PageSize, CurPage, qStr, "SupplyName,Spell,Address").Tables[0];
        Store_Supply.DataSource = suppData;
        Store_Supply.DataBind();
    }

    private string GetSupplyQryString()
    {
        string StrSql = "DelState=0 ";
        string selText = FilterSpecChar(extcomb_SupplyId.SelectedItem.Text.Trim());
        if (!string.IsNullOrEmpty(selText))
            StrSql += " and ( SupplyName like '%" + selText + "%' or Spell like '%" + selText + "%') ";
        return StrSql;
    }


    /// <summary>
    /// 保存，
    /// </summary>
    /// <param name="jsonData"></param>
    /// <param name="type">0,保存;1,提交;2,审核</param>
    [DirectMethod]
    public void SaveData(int type)
    {
        CRMMis.Model.ERP_ExportBll inStoreModel;
        if (ViewState_ObjID == "Add")
        {
            inStoreModel = new CRMMis.Model.ERP_ExportBll();
            inStoreModel.ExportBillId = CRMMis.BLL.ERP_ExportBll.GetNewID();
            inStoreModel.ExportBillNo = GetBusinessNo("RK", "ERP_ExportBllRK", Convert.ToInt32(extcomb_StoreRoomId.Value).ToString("000"));
            inStoreModel.InUser = BS_LoginUserID;
            inStoreModel.InDate = exttxtf_InDate.Text.Trim();
            inStoreModel.State = 0;
            if (type == 1)
                inStoreModel.State = 1;    //提交
        }
        else
        {
            inStoreModel = CRMMis.BLL.ERP_ExportBll.GetModel(Convert.ToInt32(ViewState_ObjID));
            if (type == 1)
            {
                if (inStoreModel.State == 0)
                    inStoreModel.State = 1;   //提交
                else
                {
                    X.Msg.Alert("系统提示", "提交失败！当前记录已经提交").Show();
                    return;
                }
            }
            else if (type == 2)
            {
                if (inStoreModel.State == 1)
                    inStoreModel.State = 2;    //审核
                else
                {
                    X.Msg.Alert("系统提示", "审核失败！当前记录已经审核").Show();
                    return;
                }
            }

        }

        if (type < 2)
        {
            inStoreModel.ReceiptNo = exttxtf_ReceiptNo.Text.Trim();
            if (extdate_ReceiptDate.SelectedValue != null)
                inStoreModel.ReceiptDate = extdate_ReceiptDate.SelectedDate.ToString();
            inStoreModel.ReceiptMoney = Convert.ToDecimal(extnumf_ReceiptMoney.Value ?? 0);
            inStoreModel.StoreRoomId = Convert.ToInt32(extcomb_StoreRoomId.Value);
            inStoreModel.SupplyId = Convert.ToInt32(extcomb_SupplyId.Value);
            inStoreModel.Remark = exttxtf_Remark.Text.Trim();
        }

        CommonLib.BLL.MyTransaction myTrans = new CommonLib.BLL.MyTransaction();
        myTrans.BeginTransaction();
        try
        {
            if (ViewState_ObjID == "Add")
            {
                CRMMis.BLL.ERP_ExportBll.Add(myTrans, inStoreModel);
            }
            else
            {
                CRMMis.BLL.ERP_ExportBll.Update(myTrans, inStoreModel);
                //删除子表
                if (type < 2)
                    CRMMis.BLL.ERP_ExportDetail.DeleteFK(myTrans, "DExportBillId = " + inStoreModel.ExportBillId);
                //处理审核
                if (type == 2)
                    CheckInfo(myTrans, inStoreModel);
            }
            if (type < 2)
            {
                int i = 1;
                foreach (DataRow item in ViewState_InStoreList.Rows)
                {
                    CRMMis.Model.ERP_ExportDetail detailModel = new CRMMis.Model.ERP_ExportDetail();
                    detailModel.ItemlId = CRMMis.BLL.ERP_ExportDetail.GetNewID();
                    detailModel.DExportBillId = inStoreModel.ExportBillId;
                    detailModel.OrderId = i;
                    detailModel.Count = Convert.ToInt32(item["Count"]);
                    detailModel.DetailId = Convert.ToInt32(item["DetailId"]);
                    detailModel.BatchNo = item["BatchNo"].ToString();
                    detailModel.ProduceDate = Convert.ToDateTime(item["ProduceDate"]).ToString();
                    detailModel.DisinfectionDate = Convert.ToDateTime(item["DisinfectionDate"]).ToString();
                    detailModel.ExpiryDate = Convert.ToDateTime(item["ExpiryDate"]).ToString();
                    detailModel.AsepticDate = Convert.ToDateTime(item["AsepticDate"]).ToString();

                    CRMMis.BLL.ERP_ExportDetail.Add(myTrans, detailModel);
                    i++;
                }
            }
            myTrans.CommitTran();
            ViewState_ObjID = inStoreModel.ExportBillId.ToString();
            exttxtf_ExportBillNo.Text = inStoreModel.ExportBillNo;

            string handler = "";
            if (type > 0)
                handler = "closeCurrTab();";
            X.Msg.Alert("系统提示", "保存成功！", handler).Show();
        }
        catch(Exception ex)
        {
            myTrans.RollBackTran();
            X.Msg.Alert("系统提示", "保存失败！</br>" + ex.Message).Show();
        }
    }

    #region 修改列表

    [DirectMethod]
    public void GetBasicInfo(string jsonText, string ObjId)
    {
        if (string.IsNullOrEmpty(jsonText))
            return;
        if (string.IsNullOrEmpty(extcomb_StoreRoomId.Text.Trim()))
            return;
        try
        {
            Dictionary<string, string> JsonObj = JSON.Deserialize<Dictionary<string, string>>(jsonText);
            DataTable dtCargo_Detail = CRMMis.BLL.ERP_Cargo_Detail.GetList("DetailId=" + JsonObj["DetailId"] + " and State=1 ").Tables[0];
            if (dtCargo_Detail.Rows.Count < 1)
            {
                X.Msg.Alert("系统提示", "该商品没有目录信息，无法添加").Show();
                return;
            }
            DataRow dr = dtCargo_Detail.Rows[0];
            foreach (DataColumn col in dtCargo_Detail.Columns)
            {
                if (JsonObj.ContainsKey(col.ColumnName))
                    continue;
                JsonObj.Add(col.ColumnName, dr[col.ColumnName].ToString());
            }

            int num = Convert.ToInt32(JsonObj["Count"]);
            AddMatList(ObjId, JsonObj, num);
        }
        catch (Exception ex)
        {
            X.Msg.Alert("系统提示", "转换时出错|" + ex.Message).Show();
        }
    }

    private void AddMatList(string ObjId, Dictionary<string, string> JsonObj, int num)
    {
        if (ViewState_InStoreList == null)
            return;
        
        DataRow dr = ViewState_InStoreList.NewRow();

        if (ObjId != "Add")
            dr = ViewState_InStoreList.Select("ItemlId=" + ObjId).FirstOrDefault();
        else
        {
            DataRow row = ViewState_InStoreList.Select("DetailId=" + JsonObj["DetailId"] + " and BatchNo='" + JsonObj["BatchNo"] + "'").FirstOrDefault();
            if (row != null)    //存在改数量
            {
                dr = row;
                num += Convert.ToInt32(dr["Count"]);
                ObjId = dr["ItemlId"].ToString();
            }
            else
            {          //不存在新增
                dr["ItemlId"] = CRMMis.BLL.ERP_ExportDetail.GetNewID().ToString(); //GetItemIdId(JsonObj["DetailId"], JsonObj["BatchNo"]);
                dr["DetailId"] = JsonObj["DetailId"];
                dr["BatchNo"] = JsonObj["BatchNo"];
                if (!string.IsNullOrEmpty(JsonObj["ProduceDate"]))
                {
                    dr["ProduceDate"] = JsonObj["ProduceDate"];
                    if (!JsonObj.ContainsKey("HAS_VALID") || JsonObj["HAS_VALID"].ToUpper() == "TRUE")
                        dr["ExpiryDate"] = JsonObj["ExpiryDate"];
                    else
                        dr["ExpiryDate"] = new DateTime(9999, 12, 31);
                }
                dr["DisinfectionDate"] = JsonObj["DisinfectionDate"];
                dr["AsepticDate"] = JsonObj["AsepticDate"];
            }
        }

        //计算的数据
        dr["Count"] = num;
        dr["TotalPrice"] = Convert.ToDecimal(JsonObj["Supplyprice"]) * num;
        dr["Supplyprice"] = JsonObj["Supplyprice"];
        //获取的数据
        dr["CargoName"] = JsonObj["CargoName"];
        dr["CargoCode"] = JsonObj["CargoCode"];
        dr["Spec"] = JsonObj["Spec"];
        dr["Version"] = JsonObj["Version"];
        dr["ProduceName"] = JsonObj["ProduceName"];
        dr["Area"] = JsonObj["Area"];
        dr["BatchNo"] = JsonObj["BatchNo"];

        if (ObjId == "Add")
            ViewState_InStoreList.Rows.Add(dr);
        Store1.DataSource = ViewState_InStoreList;
        Store1.DataBind();
        extcomb_SupplyId.ReadOnly = extcomb_StoreRoomId.ReadOnly = ViewState_InStoreList.Rows.Count > 0;
    }

    [DirectMethod]
    public void RemoveItem(int itemid)
    {
        DataRow selRow = ViewState_InStoreList.Select("ItemlId=" + itemid).FirstOrDefault();
        if (selRow != null)
            ViewState_InStoreList.Rows.Remove(selRow);
        Store1.DataSource = ViewState_InStoreList;
        Store1.DataBind();
        extcomb_SupplyId.ReadOnly = extcomb_StoreRoomId.ReadOnly = ViewState_InStoreList.Rows.Count > 0;
    }

    #endregion

    /// <summary>
    /// 处理审核
    /// </summary>
    /// <param name="myTrans"></param>
    /// <param name="inStoreModel"></param>
    public void CheckInfo(CommonLib.BLL.MyTransaction myTrans, CRMMis.Model.ERP_ExportBll inStoreModel)
    {
        inStoreModel.CheckUser = BS_LoginUserID;
        inStoreModel.CheckDate = DateTime.Now.ToString();
        inStoreModel.State = 2;
        CRMMis.BLL.ERP_ExportBll.Update(myTrans, inStoreModel);

        ViewState_InStoreList = CRMMis.BLL.ERP_ExportDetail.GetList(myTrans, " DExportBillId=" + inStoreModel.ExportBillId, "OrderId").Tables[0];
        foreach (DataRow row in ViewState_InStoreList.Rows)
        {
            CRMMis.Model.ERP_BusinessLog BusModel = new CRMMis.Model.ERP_BusinessLog();
            BusModel.LogId = CRMMis.BLL.ERP_BusinessLog.GetNewID();
            BusModel.ActionId = 1;
            BusModel.ActionName = "入库";
            BusModel.ActionUser = inStoreModel.InUser;
            BusModel.StoreRoom_Id = inStoreModel.StoreRoomId.ToString();
            BusModel.ActionDate = inStoreModel.CheckDate;
            
            //ERP_StockInfo 表
            var model = CRMMis.BLL.ERP_StockInfo.GetModel(myTrans, "DetailId=" + row["DetailId"]);
            if (model != null)
            {
                BusModel.CurCount = model.Count;
                BusModel.Count = Convert.ToInt32(row["Count"]);
                model.Count += Convert.ToInt32(row["Count"]);
                CRMMis.BLL.ERP_StockInfo.Update(myTrans, model);
            }
            else
            {
                BusModel.CurCount = 0;
                BusModel.Count = Convert.ToInt32(row["Count"]);
                model = new CRMMis.Model.ERP_StockInfo();
                model.StoreId = CRMMis.BLL.ERP_StockInfo.GetNewID();
                model.DetailId = Convert.ToInt32(row["DetailId"]);
                model.StoreRoomId = Convert.ToInt32(row["StoreRoomId"]);
                model.Count = Convert.ToInt32(row["Count"]);
                CRMMis.BLL.ERP_StockInfo.Add(myTrans, model);
            }
            BusModel.DetailId = model.DetailId;
            DataTable dt = CRMMis.BLL.ERP_Cargo_Detail.GetList("DetailId="+model.DetailId).Tables[0];
            BusModel.CargoName = dt.Rows[0]["CargoName"].ToString();
            BusModel.Spec = dt.Rows[0]["Spec"].ToString();
            BusModel.Area = dt.Rows[0]["Area"].ToString();
            BusModel.Version = dt.Rows[0]["Version"].ToString();
            BusModel.ProduceName = dt.Rows[0]["ProduceName"].ToString();
            BusModel.BatchNo = row["BatchNo"].ToString();
            BusModel.SupplyPrice = decimal.Parse(dt.Rows[0]["SupplyPrice"].ToString());
            //ERP_StockDetail 表
            var stockDetail = CRMMis.BLL.ERP_StockDetail.GetModel(myTrans, "StoreId=" + model.StoreId + " and BatchNo='" + row["BatchNo"] + "'");
            if (stockDetail != null)
            {
               
                stockDetail.Count+= Convert.ToInt32(row["Count"]);
                CRMMis.BLL.ERP_StockDetail.Update(myTrans, stockDetail);
            }
            else
            {
                stockDetail = new CRMMis.Model.ERP_StockDetail();
                stockDetail.ItemId = CRMMis.BLL.ERP_StockDetail.GetNewID();
                stockDetail.StoreId = model.StoreId;
                stockDetail.BatchNo = row["BatchNo"].ToString();
                stockDetail.ProduceDate = row["ProduceDate"].ToString();
                stockDetail.DisinfectionDate = row["DisinfectionDate"].ToString();
                stockDetail.ExpiryDate = row["ExpiryDate"].ToString();
                stockDetail.AsepticDate = row["AsepticDate"].ToString();
                stockDetail.Count = Convert.ToInt32(row["Count"]);
                CRMMis.BLL.ERP_StockDetail.Add(myTrans, stockDetail);
            }
            BusModel.State = 0;
            BusModel.BusniessNo = inStoreModel.ExportBillNo;
            CRMMis.BLL.ERP_BusinessLog.Add(myTrans,BusModel);
        }
    }


    #region Excel导入

    ///<summary>
    /// 上传Excel
    ///</summary>
    [DirectMethod]
    public void ImportExcel()
    {
        if (extcomb_SupplyId.Text == "")
        {
            X.Msg.Alert("系统提示", "请先选择供货商！").Show();
            return;
        }
        if (extFuf_ImportExcel.HasFile)
        {
            string strExt = string.Empty;
            string strName = "";
            string strPathName = "";
            string sSize = "";

            if (extFuf_ImportExcel.PostedFile != null && extFuf_ImportExcel.PostedFile.ContentLength > 0)
            {
                strName = extFuf_ImportExcel.PostedFile.FileName;
                sSize = extFuf_ImportExcel.PostedFile.ContentLength.ToString();
                strExt = System.IO.Path.GetExtension(strName);
                strPathName = Guid.NewGuid().ToString() + strExt;
                if (strExt.ToUpper() != ".XLS")
                {
                    X.Msg.Alert("提示", "Excel格式应为.xls", MessageBox.Icon.WARNING).Show();
                    return;
                }
            }

            string strMapPath = Server.MapPath("../TmpFile/");
            string strPath = strMapPath + strPathName;
            extFuf_ImportExcel.PostedFile.SaveAs(strPath);
            OpenExcel(strPath, strExt);
        }
        else
        {
            X.Msg.Alert("提示", "请选择Excel", MessageBox.Icon.NONE).Show();
        }
    }


    public DataTable SessionImportDetailExcel { get; set; }

    private void OpenExcel(string filePath, string strExt)
    {
        System.IO.FileStream stream = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);//读入excel模板
        IWorkbook Iworkbook = null;
        if (strExt.ToUpper() == ".XLSX") // 2007版本,不能用,暂时不启用
            Iworkbook = new XSSFWorkbook(stream);
        else if (strExt.ToUpper() == ".XLS") // 2003版本
            Iworkbook = new HSSFWorkbook(stream);

        //处理模板数据
        ISheet sheet = Iworkbook.GetSheetAt(0);

        IRow headerRow = sheet.GetRow(0);
        int cellCount = headerRow.LastCellNum;  //LastCellNum = PhysicalNumberOfCells
        int rowCount = sheet.LastRowNum;        //LastRowNum = PhysicalNumberOfRows - 1

        SessionImportDetailExcel = new DataTable();
        
        foreach (var column in gridPanel_listdata.ColumnModel.Columns)
        {
            SessionImportDetailExcel.Columns.Add(column.DataIndex);
        }

        for (int i = (sheet.FirstRowNum + 1); i <= rowCount; i++)
        {
            IRow row = sheet.GetRow(i);
            DataRow dataRow = SessionImportDetailExcel.NewRow();

            if (row != null)
            {
                //dataRow["ItemlId"] = i;
                for (int j = row.FirstCellNum; j < cellCount; j++)
                {
                    if (row.GetCell(j) != null)
                    {
                        string val = GetCellValue(row.GetCell(j));
                        dataRow[j + 1] = val;
                    }
                }
            }
            SessionImportDetailExcel.Rows.Add(dataRow);
        }
        SetExcelData();

    }

    /// <summary>
    /// 根据Excel列类型获取列的值
    /// </summary>
    /// <param name="cell">Excel列</param>
    /// <returns></returns>
    private static string GetCellValue(ICell cell)
    {
        if (cell == null)
            return string.Empty;
        switch (cell.CellType)
        {
            case CellType.Blank:
                return string.Empty;
            case CellType.Boolean:
                return cell.BooleanCellValue.ToString();
            case CellType.Error:
                return cell.ErrorCellValue.ToString();
            case CellType.Numeric:
            case CellType.Unknown:
            default:
                return cell.ToString();
            case CellType.String:
                return cell.StringCellValue;
            case CellType.Formula:
                try
                {
                    HSSFFormulaEvaluator e = new HSSFFormulaEvaluator(cell.Sheet.Workbook);
                    e.EvaluateInCell(cell);
                    return cell.ToString();
                }
                catch
                {
                    return cell.NumericCellValue.ToString();
                }
        }
    }

    private void SetExcelData()
    {
        ViewState_InStoreList = CRMMis.BLL.ERP_ExportDetail.GetList("1=2").Tables[0];
        string tmp = " State=1 and CargoName='{0}' and Spec='{1}' and Version='{2}' and ProduceName='{3}' and Area='{4}' ";//and Supplyprice={5} 
        //extcomb_SupplyId.SelectedItem.Value + "&storeroomId=" + extcomb_StoreRoomId.SelectedItem.Value
        tmp += " and SupplyId=" + extcomb_SupplyId.SelectedItem.Value;
        int index = 2;
        foreach (DataRow row in SessionImportDetailExcel.Rows)
        {
            DataTable dtCargo_Detail = CRMMis.BLL.ERP_Cargo_Detail.GetList(string.Format(tmp, row["CargoName"], row["Spec"], row["Version"], row["ProduceName"], row["Area"])).Tables[0];
            if (dtCargo_Detail.Rows.Count < 1)
            {
                X.Msg.Alert("系统提示", "第" + index + "行,该商品没有目录信息，无法添加").Show();
                return;
            }
            DataRow dr = dtCargo_Detail.Rows[0];
            var nrow = ViewState_InStoreList.NewRow();
            nrow["CargoName"] = dr["CargoName"];
            nrow["Spec"] = dr["Spec"];
            nrow["Version"] = dr["Version"];
            nrow["ProduceName"] = dr["ProduceName"];
            nrow["Area"] = dr["Area"];
            nrow["Supplyprice"] = dr["Supplyprice"];
            nrow["DetailId"] = dr["DetailId"];
            nrow["Count"] = row["Count"];
            nrow["BatchNo"] = row["BatchNo"];
            nrow["ProduceDate"] = Convert.ToDateTime(row["ProduceDate"]);
            nrow["DisinfectionDate"] = Convert.ToDateTime(row["DisinfectionDate"]);
            nrow["ExpiryDate"] = Convert.ToDateTime(row["ExpiryDate"]);
            nrow["AsepticDate"] = Convert.ToDateTime(row["AsepticDate"]);
            nrow["TotalPrice"] = Convert.ToInt32(row["Count"]) * Convert.ToDecimal(dr["Supplyprice"]);
            nrow["ItemlId"] = -index;
            ViewState_InStoreList.Rows.Add(nrow);
            index++;
        }
        Store1.DataSource = ViewState_InStoreList;
        Store1.DataBind();

    }


    #endregion

}